package org.roger.search;

import java.io.IOException;

import org.apache.lucene.index.Term;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.BytesRef;
import org.roger.search.filter.LuceneSearchFilter;
import org.roger.search.filter.RangeFilter;

/**
 * 单条件搜索
 * @param field 所搜的字段 
 * @param keyword 匹配的关键字
 */
public class SingleSearch extends LuceneSearchBase{
	
	private String field;
	private String keyword;
	
	public SingleSearch(String field,String keyword){
		this.field = field;
		this.keyword = keyword;
	}

	@Override
	public Query getSearchQuery() {
		//TermQuery termQuery = new TermQuery(new Term(field,keyword));
		TermQuery termQuery = new TermQuery(new Term(field,new BytesRef(keyword)));
		System.out.println(termQuery.toString());
		return termQuery;
	}
	
	public static void main(String[] args) {
		SingleSearch search = new SingleSearch("content", "修改");
		try {
			Long s1 = System.currentTimeMillis();
			search.search("E:/lucene/index");
			System.out.println("cost time:"+(System.currentTimeMillis()-s1));
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public Filter getFilter() {
//		LuceneSearchFilter filter = new RangeFilter<Integer>("id",1,3,true,true,false);
//		return filter.searchFilter();
		return null;
	}

	@Override
	public Sort getSort() {
//		Sort sort = new Sort(
//		new SortField("id",SortField.Type.INT,true),
//		new SortField("modified",SortField.Type.LONG));
		//按照索引顺序进行排序
//		Sort sort = Sort.INDEXORDER;
		return null;
	}
}
